﻿using System;
using CacheManager.Core;
using KL.UFrame.Core.Unity;
using KL.UFrame.Data.Entities;

namespace KL.UFrame.Data.Business
{
    /// <summary>
    /// 业务基类
    /// By：杨超
    /// QQ：489578430
    /// </summary>
    public abstract class BusinessBase:IDisposable
    {
        /// <summary>
        /// EF DbContext
        /// </summary>
        protected readonly ApplicationDbContext Db = UnityBootstrapper.Current.GetService<ApplicationDbContext>();

        /// <summary>
        /// 缓存组件
        /// </summary>
        protected readonly ICacheManager<object> Cache = UnityBootstrapper.Current.GetInstance<ICacheManager<object>>();

        #region IDisposable

        public void Dispose()
        {
            Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    Db.Dispose();
                }
                catch 
                {
                    //ignore
                }
            }
        }
        #endregion


        #region Protected 方法

        #endregion
    }
}
